home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n05.arc / FALOG.ASM < prev    next >
Assembly Source File  |  1990-02-13  |  3KB  |  73 lines

  1.         title   FALOG.ASM Calculate Common Antilog on 80x87
  2.         page    55,132
  3.  
  4. ; FALOG.ASM --- Calculate Common Antilog on 80x87
  5. ;
  6. ; Copyright (C) 1989 Ziff Davis Communications
  7. ; PC Magazine * Ray Duncan
  8. ;
  9. ; Call with:    ST(0)     = argument
  10. ;
  11. ; Returns:      ST(0)     = antilog to base 10
  12. ;
  13. ; Uses:         CPU registers are preserved; 
  14. ;               uses 3 cells of coprocessor stack
  15. ;
  16. ; Note:         To obtain natural antilog, replace
  17. ;               "fldl2t" instruction with "fldl2e".
  18. ;
  19. ; Make sure coprocessor has been properly initialized
  20. ; with a previous call to INIT87!
  21.  
  22. _TEXT   segment word public 'CODE'
  23.  
  24.         assume  cs:_TEXT
  25.  
  26. oldcw   equ     word ptr [bp-4]         ; original control word
  27. newcw   equ     word ptr [bp-2]         ; new control word
  28.  
  29.         public  falog
  30. falog   proc    near
  31.  
  32.         push    ax                      ; save registers and
  33.         push    bp                      ; make stack frame
  34.         mov     bp,sp                   ; for local variables
  35.         sub     sp,4
  36.         fldl2t                          ; load log2(10)
  37.         fmulp   st(1),st(0)             ; log2(10) * argument
  38.         fld     st(0)                   ; duplicate product
  39.         fstcw   oldcw                   ; get old control word
  40.         fwait                           ; wait till it arrives
  41.         mov     ax,oldcw                ; change rounding mode
  42.         and     ax,0f3ffh               ; field to "round down"
  43.         or      ax,0400h
  44.         mov     newcw,ax
  45.         fldcw   newcw                   ; force rounding mode
  46.         frndint                         ; get int part of product
  47.         fldcw   oldcw                   ; restore old rounding mode
  48.         fld     st(0)                   ; duplicate integer part
  49.         fxch    st(2)                   ; get original product
  50.         fsubrp  st(1),st(0)             ; find fractional part
  51.         fld1
  52.         fchs
  53.         fxch    st(1)                   ; scale fractional part
  54.         fscale
  55.         fstp    st(1)                   ; discard coprocessor junk      
  56.         f2xm1                           ; raise 2 to power-1
  57.         fld1
  58.         faddp   st(1),st(0)             ; correct for the -1
  59.         fmul    st(0),st(0)             ; square result
  60.         fscale                          ; scale by int part
  61.         fstp    st(1)                   ; discard coprocessor junk
  62.         add     sp,4                    ; discard local variables
  63.         pop     bp                      ; restore registers and
  64.         pop     ax                      ; return result in ST(0)
  65.         ret
  66.  
  67. falog   endp
  68.  
  69. _TEXT   ends
  70.  
  71.         end
  72.  
  73.